<%-- 
    Document   : major
    Created on : Nov 25, 2009, 11:41:15 AM
    Author     : kossel
--%>

<%--Jquery Functions--%>
    <code>
        <script src="../js/jquery-1.3.2.js" type="text/javascript"></script>
                 <script src="../js/jquery.alerts.js" type="text/javascript"></script>
                 <link href="../css/jquery.alerts.css" rel="stylesheet" type="text/css" />
                                  <%-- jquery ui --%>
                 <link type="text/css" href="../css/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
                 <script type="text/javascript" src="../js/jquery-ui-1.7.2.custom.min.js"></script>

          

            <code>
                <script type="text/javascript" charset="utf-8">
                       var semester;
                       $(document).ready(function() {
                            $("#subjectForm").hide();
                            //$("#reticle").hide();
                            $("#subjectRow").hide();
                            $("#showAddSubject").click(function(){
                                $("#subjectForm").show("slow");
                            });

                            $("#curriculumListBox").change(function(){
                                var selected = $("#curriculumListBox").val();
                                if(selected!="0"){$("#subjectRow").show();
                                    
                                    var id=$("#curriculumListBox").val();
                                    $.getJSON("getCurriculumSemester.do", {id:id}, function(response){
                                       semester=response.key;
                                    });

                                }else{$("#subjectRow").hide();

                            }
                            });

                            $("#addToCurriculum").click(function(){
                               var id=$("#subjectsListBox").val();
                               if(id=="0"){return false;}
                               $.post("getSubjectJSON.do", {id:id}, function(response){
                                var id=response.key;
                                var name=response.name;
                                var credit=response.credits;
                                var hrs=response.hr;
                                var options;
                                for(i=0; i<semester; i++){
                                        options =options+"<option value=\""+(i+1)+"\">"+(i+1)+"</option>"
                                                        }
                                var subject='<tr id="row'+id+'">'+
                                                "<td>"+id+"</td>"+
                                                "<td>"+name+"</td>"+
                                                "<td>"+credit+"</td>"+
                                                "<td>"+hrs+"</td>"+
                                                "<td>"+"<select id=\"totalSemester\">"+
                                                        options+
                                                "</select></td>"+
                                                '<td><input type="button" class="deleteSubject" id="'+id+'" value="eliminar"/></td>'+
                                            "</tr>";
                                $("#bodySubjectList").append(subject);
                                }, "json");

                                $(".deleteSubject").click(function(){
                                    var id=$(this).attr("id");                                    
                                    $("#row"+id).remove();
                                   // $("#reticleTable").apend();
                                    //return false;
                           });



                            });

                            $("#subjectForm").submit(function(){
                                $("#subjectForm").hide();
                                $.post("addSubject.do", $(this).serialize(), function(response){
                                    if(response=="success"){
                                    var subjectKey=$("#subjectKey").val();
                                    var subjectName=$("#subjectName").val();
                                    $("#subjectsListBox").append('<option value="'+subjectKey+'">'+subjectName+'</option>');
                                    jAlert("Se agrego una materia exitosamente", "Materia")
                                    }else   jAlert(response, "Error");
                                }, "html");
                                return false;
                            });

                        } );
                </script>
            </code>
        <!--End Load Carrera-->
    </code>
<%--End Jquery Functions--%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>


<html:errors/>
<html:form action="/adminMajor/addSubject" styleId="subjectForm">

    <table class="fields">
        <tr>
            <td align="right"><bean:message key="label.subject.subjectID"/>:</td>
            <td><html:text property="subjectID" styleId="subjectKey" name="subjectForm" /></td>
        </tr>
        <tr>
            <td align="right"><bean:message key="label.subject.name"/>:</td>
            <td><html:text property="subjectName" styleId="subjectName" name="subjectForm"/> </td>
        </tr>
        <tr>
            <td align="right"><bean:message key="label.subject.NumCredits"/>:</td>
            <td><html:text property="subjectCredits" styleId="subjectCredit" name="subjectForm"/> </td>
        </tr>
        <tr>
            <td align="right"><bean:message key="label.subject.totalHrs"/>:</td>
            <td><html:text property="subjectTotalHr" styleId="subjectTotalHr" name="subjectForm"/> </td>
        </tr>
        <tr>
            <td></td>
            <td><html:submit titleKey="label.button.add"/></td>
        </tr>
    </table>     

</html:form>

<html:form action="/adminMajor/setReticle" styleId="reticleTable" >
    <table class="fields">
        <tr>
            <td align="right"><bean:message key="label.curriculum.curriculumName"/>:</td>
            <td><html:select property="ID_Curriculum" styleId="curriculumListBox" >
                            <html:option value="0">--Seleccion un plan de estudio--</html:option>
                            <html:options collection="curriculumList" labelProperty="curriculumName" property="ID_Curriculum" styleClass="ID_Curriculum" />
                </html:select>
            </td>
        </tr>
        <tr id="subjectRow">
            <td align="right"><bean:message key="label.subject.name"/>:</td>
            <td><html:select property="subjectKey" styleId="subjectsListBox" >
                            <html:option value="0">--Seleccion una materia--</html:option>
                            <html:options collection="subjectList" labelProperty="subjectName" property="subjectKey" />
                </html:select>
            </td>
            <td>
                <html:link href="#" styleId="addToCurriculum"><bean:message key="label.button.add"/></html:link>

            </td>
            <td></td>
            <td>
                <html:link href="#" styleId="showAddSubject">agregar nueva materia</html:link>
            </td>

        </tr>
    </table>

<hr noshade="true"/>
<table border="1" id="reticle" cellspacing="0" cellpadding="0">
        <thead>
            <tr>
                <th>Clave de la materia</th>
                <th>Nombre de la materia</th>
                <th>Numero de creditos</th>
                <th>Numero total de horas</th>
                <th>Semestre</th>
                <th>Operacion</th>
            </tr>
        </thead>
        <tbody id="bodySubjectList">
        </tbody>
        <tr><td colspan="6"><center><html:submit titleKey="label.button.add"/></center></td></tr>
</table>
          

</html:form>
